<?php
/**
 * Created by PhpStorm.
 * User: t
 * Date: 2024/6/24
 * Time: 11:31
 */

namespace app\admin\controller;

use app\common\model\AmountLog;
use app\common\model\LevelOrder;
use app\common\model\RechargeOrder;
use think\Request;

class  Statistics{
    public function rechargeAmount(Request $request){
        $param = $request->param();
        $levelOrderModel = new LevelOrder();
        $data['totalVipMoney'] = $levelOrderModel->where(['status' => 2])->sum('price');
        $data['todayVipMoney'] = $levelOrderModel->where(['status' => 2])->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))->sum('price');
        $data['monthVipMoney'] = $levelOrderModel->where(['status' => 2])->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))->sum('price');

        $data['yesterdayVipMoney'] = $levelOrderModel->where(['status' => 2])->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('price');
        $rechargeOrderModel = new RechargeOrder();
        $data['totalRechargeMoney'] = $rechargeOrderModel->where(['status' => 2])->sum('price');
        $data['todayRechargeMoney'] = $rechargeOrderModel->where(['status' => 2])->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))->sum('price');
        $data['monthRechargeMoney'] = $rechargeOrderModel->where(['status' => 2])->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))->sum('price');
        $data['yesterdayRechargeMoney'] = $rechargeOrderModel->where(['status' => 2])->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('price');
        $group = 'dateTime';
        $where[] = ['status','=',2];
        if (isset($param['start_time']) && !empty($param['start_time'])) {
            $where[] = ['create_time', '>=', strtotime($param['start_time'])];
        }
        if (isset($param['end_time']) && !empty($param['end_time'])) {
            $where[] = ['create_time', '<=',  strtotime($param['end_time'])];
        }
        if ($param['time_type'] == 2){
            $field  ="sum(price) as  price,date_format(from_unixtime(create_time), '%Y-%m-%d') as dateTime";
            $diff = strtotime($param['end_time']) - strtotime($param['start_time']);
            $days_diff = ceil($diff / (60 * 60 * 24)); // 60秒 * 60分钟 * 24小时 = 1天
            for ($i = 0; $i < $days_diff; $i++) {
                $key = date('Y-m-d', strtotime($param['start_time']) + (60 * 60 * 24 * $i));
                $amount[$key] = ['price' => 0, 'datetime' => $key];
            }
            $recharge = $rechargeOrderModel->where($where)->field($field)->group($group)->select()->toArray();

            foreach ($recharge as $value) {
                if (array_key_exists($value['dateTime'], $amount)) {
                    $amount[$value['dateTime']]['price'] = bcadd($value['price'], $amount[$value['dateTime']]['price'], 2);
                }
            }
        }else{
            $field  ="sum(price) as  price,date_format(from_unixtime(create_time), '%Y-%m-%d %H:00:00') as dateTime";
            for ($i = 0; $i <= 6; $i++) {
                 $amount[$i] = ['price' => 0, 'datetime' => $i * 4,];
            }
            $recharge = $rechargeOrderModel->where($where)->field($field)->group($group)->select()->toArray();
            foreach ($recharge as $value) {
                if (date('H', strtotime($value['dateTime'])) / 4 > 0) {
                    $amount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['price'] =
                        bcadd($value['price'], $amount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['price'], 2);
                }
            }
        }
        $data['recharge_kline'] = array_values($amount);
        return success('金额',$data);
    }
    public function rechargeOrder(Request $request){
        $param = $request->param();
        $limit = 10;
        $start = 0;
        if (isset($param['limit']) && !empty($param['limit'])) {
            $limit = $param['limit'];
        }
        if (isset($param['page']) && !empty($param['page'])) {
            $start = ($param['page'] - 1) * $limit;
        }
        $where = [];
        if (isset($param['nickname']) && !empty($param['nickname'])) {
            $where[] = ['nickname','like','%'.$param['nickname'].'%'];
        }
        if (isset($param['status']) && !empty($param['status'])) {
            $where[] = ['re.status','=',$param['status']];
        }
        $rechargeOrderModel = new \app\common\model\RechargeOrder();
        $list = $rechargeOrderModel ->alias('re')
            ->leftJoin('user u','re.uid = u.id')
            ->where($where)
            ->field('re.*,u.nickname,u.avatar')
            ->limit($start, $limit)
            ->select()->toArray();
        $count = $rechargeOrderModel ->alias('re')
            ->leftJoin('user u','re.uid = u.id')
            ->where($where)->count();
        return success('充值记录', ['list' => $list, 'count' => $count]);
    }
    public function withdrawal(Request $request)
    {
        $withdrawalModel  = new \app\common\model\Withdrawal();
        $data['withdrawal_total_count'] = $withdrawalModel->where(['status' => 3])->count();
        $data['withdrawal_today_count'] = $withdrawalModel->where(['status' => 3])->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))->count();
        $data['withdrawal_month_count'] = $withdrawalModel->where(['status' => 3])->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))->count();
        $data['withdrawal_yesterday_count'] = $withdrawalModel->where(['status' => 3])->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->count();
        $data['withdrawal_total_amount'] = $withdrawalModel->where(['status' => 3])->sum('amount');
        $data['withdrawal_today_amount'] = $withdrawalModel->where(['status' => 3])->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))->sum('amount');;
        $data['withdrawal_month_amount'] = $withdrawalModel->where(['status' => 3])->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))->sum('amount');;
        $data['withdrawal_yesterday_amount'] = $withdrawalModel->where(['status' => 3])->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('amount');
        $data['withdrawal_total_number'] = $withdrawalModel->where(['status' => 3])->sum('number');
        $data['withdrawal_today_number'] = $withdrawalModel->where(['status' => 3])->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))->sum('number');;
        $data['withdrawal_month_number'] = $withdrawalModel->where(['status' => 3])->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))->sum('number');;
        $data['withdrawal_yesterday_number'] = $withdrawalModel->where(['status' => 3])->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('number');

        return success('用户',$data);
    }
    public function userCount(Request $request){
        $param = $request->param();
        $userModel  = new \app\common\model\User();
        $data['user_total_count'] = $userModel->count();
        $data['user_today_count'] = $userModel->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))->count();
        $data['user_month_count'] = $userModel->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))->count();
        $data['user_yesterday_count'] = $userModel->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
          ->count();
        $group = 'dateTime';
        $where[] = ['status','=',1];
        if (isset($param['start_time']) && !empty($param['start_time'])) {
            $where[] = ['create_time', '>=', strtotime($param['start_time'])];
        }
        if (isset($param['end_time']) && !empty($param['end_time'])) {
            $where[] = ['create_time', '<=',  strtotime($param['end_time'])];
        }
        if ($param['time_type'] == 2){
            $field  ="count(*) as  count,date_format(from_unixtime(create_time), '%Y-%m-%d') as dateTime";
            $diff = strtotime($param['end_time']) - strtotime($param['start_time']);
            $days_diff = ceil($diff / (60 * 60 * 24)); // 60秒 * 60分钟 * 24小时 = 1天
            for ($i = 0; $i < $days_diff; $i++) {
                $key = date('Y-m-d', strtotime($param['start_time']) + (60 * 60 * 24 * $i));
                $userCount[$key] = ['count' => 0, 'datetime' => $key];
            }
            $userTotal = $userModel->where($where)->field($field)->group($group)->select()->toArray();
            foreach ($userTotal as $value) {
                if (array_key_exists($value['dateTime'], $userCount)) {
                    $userCount[$value['dateTime']]['count'] = bcadd($value['count'], $userCount[$value['dateTime']]['count']);
                }
            }
        }else{
            $field  ="count(*) as  count,date_format(from_unixtime(create_time), '%Y-%m-%d %H:00:00') as dateTime";
            for ($i = 0; $i <= 6; $i++) {
                $userCount[$i] = ['count' => 0, 'datetime' => $i * 4];
            }
            $userTotal = $userModel->where($where)->field($field)->group($group)->select()->toArray();
            foreach ($userTotal as $value) {
                if (date('H', strtotime($value['dateTime'])) / 4 > 0) {
                    $userCount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['count'] =
                        bcadd($value['count'], $userCount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['count']);
                }
            }
        }
        $data['user_kline'] = array_values($userCount);
        return success('用户',$data);
    }
    public function platformIncome(Request $request){
        $param = $request->param();
        $amountModel = new AmountLog();
        $levelOrderModel = new LevelOrder();
        $data['totalVipMoney'] = $levelOrderModel->where(['status' => 2])->sum('price');
        $data['todayVipMoney'] = $levelOrderModel->where(['status' => 2])->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))->sum('price');
        $data['monthVipMoney'] = $levelOrderModel->where(['status' => 2])->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))->sum('price');
        $data['yesterdayVipMoney'] = $levelOrderModel->where(['status' => 2])->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('price');

        $data['total_dazi_income'] = $amountModel->where(['operation_source' => 4])->sum('handling_fees');
        $data['today_dazi_income'] = $amountModel->where(['operation_source' => 4])
            ->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))->sum('handling_fees');
        $data['month_dazi_income'] = $amountModel->where(['operation_source' => 4])
            ->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))->sum('handling_fees');
        $data['yesterday_dazi_income'] = $amountModel->where(['operation_source' => 4])
            ->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees');
        $data['total_service_income'] = $amountModel->where(['operation_source' => 8])->sum('handling_fees');
        $data['today_service_income'] = $amountModel->where(['operation_source' => 8])
            ->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))->sum('handling_fees');
        $data['month_service_income'] = $amountModel->where(['operation_source' => 8])
            ->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))->sum('handling_fees');
        $data['yesterday_service_income'] = $amountModel->where(['operation_source' => 8])
            ->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees');
        $data['total_community_income'] = $amountModel->where(['operation_source' => 12])->sum('handling_fees');
        $data['today_community_income'] = $amountModel->where(['operation_source' => 12])
            ->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))->sum('handling_fees');
        $data['month_community_income'] = $amountModel->where(['operation_source' => 12])
            ->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))->sum('handling_fees');
        $data['yesterday_community_income'] = $amountModel->where(['operation_source' => 12])
            ->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees');


        $data['total_dazi_income_money'] = $amountModel->where(['operation_source' => 4])
            ->sum('handling_fees_amount');

        $data['today_dazi_income_money'] = $amountModel->where(['operation_source' => 4])
            ->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees_amount');

        $data['month_dazi_income_money'] = $amountModel->where(['operation_source' => 4])
            ->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))
            ->sum('handling_fees_amount');

        $data['yesterday_dazi_income_money'] = $amountModel->where(['operation_source' => 4])
            ->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees_amount');

        $data['total_service_income_money'] = $amountModel->where(['operation_source' => 8])
            ->sum('handling_fees_amount');

        $data['today_service_income_money'] = $amountModel->where(['operation_source' => 8])
            ->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees_amount');

        $data['month_service_income_money'] = $amountModel->where(['operation_source' => 8])
            ->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))
            ->sum('handling_fees_amount');

        $data['yesterday_service_income_money'] =
            $amountModel->where(['operation_source' => 8])
            ->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees_amount');

        $data['total_community_income_money'] = $amountModel->where(['operation_source' => 12])
                ->sum('handling_fees_amount');

        $data['today_community_income_money'] =
            $amountModel->where(['operation_source' => 12])
            ->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees_amount');

        $data['month_community_income_money'] = $amountModel->where(['operation_source' => 12])
            ->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))
            ->sum('handling_fees_amount');

        $data['yesterday_community_income_money'] = $amountModel->where(['operation_source' => 12])
            ->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees_amount');

        $rechargeOrderModel = new RechargeOrder();
        $data['totalRechargeMoney'] = $rechargeOrderModel->where(['status' => 2])->sum('price');
        $data['todayRechargeMoney'] = $rechargeOrderModel->where(['status' => 2])->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))->sum('price');
        $data['monthRechargeMoney'] = $rechargeOrderModel->where(['status' => 2])->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))->sum('price');
        $data['yesterdayRechargeMoney'] = $rechargeOrderModel->where(['status' => 2])->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('price');

        $group = 'dateTime';
        if (isset($param['start_time']) && !empty($param['start_time'])) {
            $where[] = ['create_time', '>=', strtotime($param['start_time'])];
        }
        if (isset($param['end_time']) && !empty($param['end_time'])) {
            $where[] = ['create_time', '<=',  strtotime($param['end_time'])];
        }
        if ($param['time_type'] == 2){
            $field  ="sum(handling_fees) as  handling_fees,date_format(from_unixtime(create_time), '%Y-%m-%d') as dateTime";
            $diff = strtotime($param['end_time']) - strtotime($param['start_time']);
            $days_diff = ceil($diff / (60 * 60 * 24)); // 60秒 * 60分钟 * 24小时 = 1天
            for ($i = 0; $i < $days_diff; $i++) {
                $key = date('Y-m-d', strtotime($param['start_time']) + (60 * 60 * 24 * $i));
                $daziAmount[$key] = ['handling_fees' => 0, 'datetime' => $key];
                $serviceAmount[$key] = ['handling_fees' => 0, 'datetime' => $key];
                $communityAmount[$key] = ['handling_fees' => 0, 'datetime' => $key];
            }
            $daziAmountLog = $amountModel->where($where)->field($field)->where(['operation_source' => 4])->group($group)->select()->toArray();
            $serviceAmountLog = $amountModel->where($where)->field($field)->where(['operation_source' => 8])->group($group)->select()->toArray();
            $communityAmountLog = $amountModel->where($where)->field($field)->where(['operation_source' => 12])->group($group)->select()->toArray();
            foreach ($daziAmountLog as $value) {
                if (array_key_exists($value['dateTime'], $daziAmount)) {
                    $daziAmount[$value['dateTime']]['handling_fees'] = bcadd($value['handling_fees'], $daziAmount[$value['dateTime']]['handling_fees'], 2);
                }
            }
            foreach ($serviceAmountLog as $value) {
                if (array_key_exists($value['dateTime'], $serviceAmount)) {
                    $serviceAmount[$value['dateTime']]['handling_fees'] = bcadd($value['handling_fees'], $serviceAmount[$value['dateTime']]['handling_fees'], 2);
                }
            }
            foreach ($communityAmountLog as $value) {
                if (array_key_exists($value['dateTime'], $communityAmount)) {
                    $communityAmount[$value['dateTime']]['handling_fees'] = bcadd($value['handling_fees'], $communityAmount[$value['dateTime']]['handling_fees'], 2);
                }
            }
        }else{
            $field  ="sum(handling_fees) as  handling_fees,date_format(from_unixtime(create_time), '%Y-%m-%d %H:00:00') as dateTime";
            for ($i = 0; $i <= 6; $i++) {
                $daziAmount[$i] = ['handling_fees' => 0, 'datetime' => $i * 4,];
                $serviceAmount[$i] = ['handling_fees' => 0, 'datetime' => $i * 4,];
                $communityAmount[$i] = ['handling_fees' => 0, 'datetime' => $i * 4,];
            }
            $daziAmountLog = $amountModel->where($where)->field($field)->where(['operation_source' => 4])->group($group)->select()->toArray();
            $serviceAmountLog = $amountModel->where($where)->field($field)->where(['operation_source' => 8])->group($group)->select()->toArray();
            $communityAmountLog = $amountModel->where($where)->field($field)->where(['operation_source' => 12])->group($group)->select()->toArray();
            foreach ($daziAmountLog as $value) {
                if (date('H', strtotime($value['dateTime'])) / 4 > 0) {
                    $daziAmount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['handling_fees'] =
                        bcadd($value['handling_fees'], $daziAmount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['handling_fees'], 2);
                }
            }
            foreach ($serviceAmountLog as $value) {
                if (date('H', strtotime($value['dateTime'])) / 4 > 0) {
                    $serviceAmount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['handling_fees'] =
                        bcadd($value['handling_fees'], $serviceAmount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['handling_fees'], 2);
                }
            }
            foreach ($communityAmountLog as $value) {
                if (date('H', strtotime($value['dateTime'])) / 4 > 0) {
                    $communityAmount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['handling_fees'] =
                        bcadd($value['handling_fees'], $communityAmount[ceil(date('H', strtotime($value['dateTime'])) / 4)]['handling_fees'], 2);
                }
            }
        }
        $data['dazi_amount'] = array_values($daziAmount);
        $data['service_amount'] = array_values($serviceAmount);
        $data['community_amount'] = array_values($communityAmount);


        $data['total_contact_income'] = bcsub(
            $amountModel->where(['operation_source' => 18])->sum('handling_fees'),
            $amountModel->where(['operation_source' => 19])->sum('handling_fees'), 2);
        $data['today_contact_income'] =bcsub(
            $amountModel->where(['operation_source' => 18])
            ->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))->sum('handling_fees'),

            $amountModel->where(['operation_source' => 19])
            ->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))->sum('handling_fees'),2);
        $data['month_contact_income'] = bcsub(
            $amountModel->where(['operation_source' => 18])
            ->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))->sum('handling_fees'),
            $amountModel->where(['operation_source' => 19])
                ->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))->sum('handling_fees'),2);
        $data['yesterday_contact_income'] =bcsub (
            $amountModel->where(['operation_source' => 18])
            ->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees'),
            $amountModel->where(['operation_source' => 19])
            ->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees'),2);

        $data['total_contact_income_money'] = $amountModel->where(['operation_source' => 18])
            ->sum('handling_fees_amount');

        $data['today_contact_income_money'] = $amountModel->where(['operation_source' => 18])
            ->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees_amount');

        $data['month_contact_income_money'] = $amountModel->where(['operation_source' => 18])
            ->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))
            ->sum('handling_fees_amount');

        $data['yesterday_contact_income_money'] = $amountModel->where(['operation_source' => 18])
            ->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees_amount');



        $data['total_dazitop_income_money'] = $amountModel->where(['operation_source' => 20])
            ->sum('handling_fees_amount');

        $data['today_dazitop_income_money'] = $amountModel->where(['operation_source' => 20])
            ->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees_amount');

        $data['month_dazitop_income_money'] = $amountModel->where(['operation_source' => 20])
            ->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))
            ->sum('handling_fees_amount');

        $data['yesterday_dazitop_income_money'] = $amountModel->where(['operation_source' => 20])
            ->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees_amount');


        $data['total_dazitop_income'] = $amountModel->where(['operation_source' => 20])
            ->sum('handling_fees');

        $data['today_dazitop_income'] = $amountModel->where(['operation_source' => 20])
            ->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees');

        $data['month_dazitop_income'] = $amountModel->where(['operation_source' => 20])
            ->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))
            ->sum('handling_fees');

        $data['yesterday_dazitop_income'] = $amountModel->where(['operation_source' => 20])
            ->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees');




        $data['total_servicetop_income_money'] = $amountModel->where(['operation_source' => 21])
            ->sum('handling_fees_amount');

        $data['today_servicetop_income_money'] = $amountModel->where(['operation_source' => 21])
            ->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees_amount');

        $data['month_servicetop_income_money'] = $amountModel->where(['operation_source' => 21])
            ->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))
            ->sum('handling_fees_amount');

        $data['yesterday_servicetop_income_money'] = $amountModel->where(['operation_source' => 21])
            ->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees_amount');


        $data['total_servicetop_income'] = $amountModel->where(['operation_source' => 21])
            ->sum('handling_fees');

        $data['today_servicetop_income'] = $amountModel->where(['operation_source' => 21])
            ->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees');

        $data['month_servicetop_income'] = $amountModel->where(['operation_source' => 21])
            ->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))
            ->sum('handling_fees');

        $data['yesterday_servicetop_income'] = $amountModel->where(['operation_source' => 21])
            ->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees');

        $data['total_chat_income_money'] = $amountModel->where(['operation_source' => 25])
            ->sum('handling_fees_amount');

        $data['today_chat_income_money'] = $amountModel->where(['operation_source' => 25])
            ->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees_amount');

        $data['month_chat_income_money'] = $amountModel->where(['operation_source' => 25])
            ->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))
            ->sum('handling_fees_amount');

        $data['yesterday_chat_income_money'] = $amountModel->where(['operation_source' => 25])
            ->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees_amount');


        $data['total_chat_income'] = $amountModel->where(['operation_source' => 25])
            ->sum('handling_fees');

        $data['today_chat_income'] = $amountModel->where(['operation_source' => 25])
            ->where('create_time','>',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees');

        $data['month_chat_income'] = $amountModel->where(['operation_source' => 25])
            ->where('create_time','>',strtotime(date('Y-m-01 00:00:00')))
            ->sum('handling_fees');

        $data['yesterday_chat_income'] = $amountModel->where(['operation_source' => 25])
            ->where('create_time','>',strtotime("yesterday"))
            ->where('create_time','<',strtotime(date('Y-m-d 00:00:00')))
            ->sum('handling_fees');

        return success('金额',$data);
    }
}